Link to this headingArgon2
- resistant to dictionary attacks, GPU attacks and ASIC attacks
Link to this headingArgon2d
- provides strong GPU resistance, but has potential side-channel attacks (possible in very special situations).
Link to this headingArgon2i
- provides less GPU resistance, but has no side-channel attacks.
Link to this headingArgon2id
- recommended (combines the Argon2d and Argon2i).
Link to this headingImplementation
#Start sanity checks so that there is no index errors
=
=
=
=
=
= 64
#Use the newest version of Argon2. This can be 0x10 and will only effect one line of code
= 0x13
#Set default to false and change if Argon2i or Argon2id is called
= False
#Derive Values from memory cost and parallelism cost
= *
= //
= >> 2
#Allocate the matrix of size column_count x self.parallelism
=
#Initialize blake2b-512
#Set Hash type for later operations
=
#Initialize the initial buffer using the blake2 algorithm with the options of the hash
# parallelism | tag_length | memory_cost | time_cost | argon_version | hash_type | len(password) | password | len(salt) | salt | len(secret) | secret | len(secret) | associated_data
=
+=
+=
+=
+=
+=
#Also add the lengths and inputs to the initial blake2 input
+=
+=
+=
+=
+=
+=
+=
+=
#Use Blake2-512 to initialize the buffer that will be used as input for the first few rounds
=
#Set type_code to 0 for Argon2d
return
#Set type_code to 1 for Argon2i
#Argon2i is data dependent
= True
return
#Set type_code to 2 for Argon2id
#Argon2id is data dependent
= True
return
#Loop through the different indexes
#initialize buffers for each (fake) parallel process
=
#For Each parallel and save them to be added to the internal buffer
#Combine the segments together with correct indexes
=
= b * 1024
#Finalize the output with 1024 length xors
=
#Do a final Blake2 variable Hash with the output and the final target tag length
return
""" This is a variable length Hash function that is baised on blake2"""
# Prepend the length of the message to prevent length extension like attacks
=
+=
#if the size is small enough then just use a single blake2 output
return
#If the output size is greater than the output of Blake2 get the first 32 bytes of the output rehash and append.
=
#Take the first 32 bytes of data
=
#Continue hashing the full digest_output and appending the first 32 bytes to the output.
=
#Add the Hash output and rehash again
+=
#Finish the output by specifying the leftover size to the Blake algorithm
+=
return
#Initialize the pseudo_rands if it is argon2i or argon2id. (The I stands for independent)
=
#Initialize the pseudo_rands with some random data generated by the parameters
= 1
# Make 1024 input block with 8 byte for each intager information
=
+=
+=
+=
+=
+=
+=
#Pad the rest of the input with null bytes
+= b *
#Send it to the compression algorithm twice
=
=
#Convert the byte string to 4 byte integers
+=
+= 1
= +
#A special first case to initialize the first two internal buffers
#Use the INITAL BUFFER derived from argon2 input data
= + +
=
# Derive Indexes from initial random values every round for Argon2i
# For Argon2id use Argon2i for the first few iterations. Then switch to Argon2d.
, = ,
# Derive current indexes from the first bytes of the previous buffer internal_buffer
=
=
# Use the second index to choose a random parallelization index from the internal buffer.
# This is used in the second argument in the _chacha_compress algorithm
%=
#Calculate the Reference Area Size to use in the calculation of the _chacha_compress second argument starting position
=
= - 1
= * - 1
= *
# same_lane
= - + - 1
= -
#Do calculation to slide the starting buffer of the _chacha_compress second argument
= - 1 -
= 0
#Possibly slide the slide the starting buffer of the _chacha_compress second argument
#Combine the calculated positions and limit it by the number of columns.
= *
= %
# Mix the previous and reference block to create the next block.
=
#This is a new case for the newest version of the argon algorithm
=
#Copy the new output data in to the correct element of the internal buffer
=
# If we are run in a separate thread, then B is a copy. Return changes.
return
#XOR the input values to be used at the end to xor before returning the data
=
=
= * 128
#Split xored data into 8 128byte rows to do a modified ChaCha Permutation on each row
+=
#For each Column Mix the values, Do a ChaCha Permutation then unmix the columns
=
#Take 16 bytes from each of the columns and reorder them
#Do a modified ChaCha Permutation on each row with the newly mixed rows. (The Old Columns)
=
#Invert the reordering of the columns and rows after the chacha permutation
=
=
#Final XOR with the original xored value with the chacha Permutation output
=
return
=
#Do Each Column
, , , =
, , , =
, , , =
, , , =
#Do Each Diagonal
, , , =
, , , =
, , , =
, , , =
return
# Modified to + 2 * a * b
# Limit the multiplication input to the first 32-bytes for input data
=
^=
=
#Modified to + 2 * c * d
# Limit the multiplication input to the first 32-bytes for input data
=
^=
=
#Modified to + 2 * a * b
# Limit the multiplication input to the first 32-bytes for input data
=
^=
=
#Modified to + 2 * c * d
# Limit the multiplication input to the first 32-bytes for input data
=
^=
=
return
= 150
= 24*8
= 24
=
=
Link to this headingUsage
https://cryptobook.nakov.com/mac-and-key-derivation/argon2